﻿using ContaPlanner.Models;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace ContaPlanner
{
    public class ToUpperConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var text = value as string;
            return string.IsNullOrEmpty(text) ? string.Empty : text.ToUpper(culture);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; }
    }

    public class StringLengthVisiblityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || value.ToString().Length == 0) return Visibility.Collapsed;
            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; }
    }

    public class CuentaExpanded : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Properties.Settings.Default.Expanded.HasFlag(((string)value).Tipo());
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; }
    }

    public class TipoAsientoDescripcion : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var tipo = (TipoAsiento)value;
            return tipo.Descripcion();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; }
    }

    public class TipoAsientoIcon : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var tipo = (TipoAsiento) value;
            switch (tipo)
            {
                case TipoAsiento.PagoTarjeta: return "\uf09d";
                case TipoAsiento.Recibo: return "\uf14a";
                case TipoAsiento.ReintegroIngreso: return "\uf01c";
                case TipoAsiento.Transferencia: return "\uf1d8";
                case TipoAsiento.Efectivo: return "\uf0d6";
                case TipoAsiento.Nomina: return "\uf02e";
            }
            return String.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; }
    }
}
